import java.util.Stack;

class MinStack {
    public Stack<Integer> stack;
    public Stack<Integer> minstack;
    public MinStack() {
        stack = new Stack<>();
        minstack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()){
            minstack.push(val);
        }else{
            int top = minstack.peek();
            if(val<=top){
                minstack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.empty()){
            return;
        }
        int peekval = stack.pop();
        if(peekval==minstack.peek()){
            minstack.pop();
        }
    }

    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(minstack.empty()){
            return -1;
        }
        return minstack.peek();
    }
}


